let cookie = {
    set: function (key, value, day) {
        if (typeof day === 'number') {
            let d = new Date();
            d.setDate(d.getDate() + day);
            document.cookie = `${key}=${value};expires=${d};path=/`;
        } else {
            document.cookie = `${key}=${value};path=/`;
        }
    },
    get: function (name) {
        let arr = decodeURIComponent(document.cookie).split('; ');
        for (let i = 0; i < arr.length; i++) {
            let newarr = arr[i].split('=');
            if (name === newarr[0]) {
                return newarr[1];
            }
        }
    },
    unset: function (name) {
        this.set(name, '', -1)
    },
    unsetAll : function () {  
		var keys = document.cookie.match(/[^ =;]+(?=\=)/g);  
		if(keys) {  
			for(var i = keys.length; i--;)  
				document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()  
		}  
	}
}

export default cookie;